package controller;

import model.Movies;
import model.OpinionThatCounts;

import java.io.IOException;



import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class LoginController
 */
public class MovieController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MovieController() {
        super();
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		OpinionThatCounts otc=new OpinionThatCounts();
		RequestDispatcher rd = null;
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		int res = otc.loginValidate(username, password);
		String choice=request.getParameter("choice");
		if(choice.equals("ViewBollywoodMovieHome"))
		{
			//userId=request.getParameter("user_id");
			//boolean flag= fq.isUserExist(userId);
			//if(flag==true)
			{
				//request.setAttribute("flag","true");
				ArrayList<Movies> movList=otc.retrieveBollywoodMovies(2);
				if(movList.size()>0)
				{
					System.out.println(movList);
					for(Movies item:movList) {   
					    System.out.print(item.toString());
					}
					request.setAttribute("movListCount", movList.size());
					rd=request.getRequestDispatcher("Movies.jsp");
					rd.forward(request,response);
					System.out.println("\n"+"hereee");
				}
			}
		}

	}
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, 
	 * 							HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, 
							HttpServletResponse response) 
							throws ServletException, IOException {
		doPost(request, response);
	}
}
